home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / Virtual User 1.0b5 / Example Libraries / FinderOperationsLib.vu next >
Encoding:
Text File  |  1990-10-05  |  2.8 KB  |  88 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        SomeFinderOperations.vu
  3. #
  4. #    Contains:    Tasks that help do some simple Finder operations like 
  5. #                  Selecting a file in a window, Trashing it.
  6. #
  7. #    Written by:    P Nagarajan
  8. #
  9. #    Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  10. #
  11. #    Change History:
  12. #
  13. #        11/7/89       naga         creation
  14. #
  15. #    To Do:
  16. #
  17.  
  18. # *****************************************************************************************
  19. task Find_object_in_window (at_x, at_y)
  20. #this task moves the mouse on to a particular object of interest. Very useful to select
  21. #files in "view by name" mode in Finder.
  22. #this assumes that the file/icon/object you want to select is on the frontmost window
  23. # with coordinates (at_x, at_y) relative to the window's origin
  24. begin
  25.     match [window o:1 r:?rect]!;
  26.     file_x := rect[1] + at_x;
  27.     file_y := rect[2] + at_y;
  28.     move a:{file_x, file_y};
  29. end;#Find_object_in_window
  30.  
  31.  
  32. # *****************************************************************************************
  33. task check_for_alert_window(override_alerts := false) 
  34. #handles alert dialogs with 'OK' and 'Cancel' buttons.
  35. #if override_alerts is true then select 'OK' else 'Cancel'
  36. begin
  37.     if(match[button w:[window ord:1 style:dialog] t:'OK']!) begin
  38.         text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
  39.         println "dismissing dialog that came up after resource type selection -- static text messages follow:";
  40.         for each m in text_messages println " ∂t",m.t;
  41.         if override_alerts select [button t:'OK' w:[window ord:1 style:dialog]]!;
  42.         else select [button t:'Cancel' w:[window ord:1 style:dialog]]!;
  43.     end;#if dialog appeared
  44. end;#check_for_alert_window
  45.  
  46.  
  47. # *****************************************************************************************
  48. task throw_trash(print_any_error := true, override_alerts := false)
  49. # this task trashes a specified object in Finder.
  50. # task assumes that the mouse is already positioned on the item to be trashed
  51. # and that the trash can is positioned on the main screen at (-40,-40) relative to
  52. # the lower right corner.
  53. # Arguements: 'print_any_error' can be used to suppress error messages and
  54. #              'override_alerts' can be used to trash despite alerts.
  55. begin
  56.     PressMouse;
  57.     match [screen r:?rect m:true]!;
  58.     if rect 
  59.     begin
  60.         trash_x := rect[3] - 40;
  61.         trash_y := rect[4] - 40;
  62.         move a:{trash_x, trash_y};
  63.         #move a:{472, 301};#trash can on a SE
  64.         ReleaseMouse;
  65.         check_for_alert_window(override_alerts);
  66.         if match [menuItem t:'Empty Trash' m:'Special' e:true]!
  67.             select [menuItem t:'Empty Trash' m:'Special']!;
  68.         else 
  69.         begin
  70.             if print_any_error
  71.                 println "Empty Trash menu item not enabled, could not trash…";
  72.             return false;
  73.         end;
  74.     end;#if unified correctly
  75.     else 
  76.     begin
  77.         if print_any_error
  78.             println "Unable to find trash can, could not trash…";
  79.         return false;
  80.     end;
  81.     return true;
  82. end; #throw_trash
  83.  
  84.  
  85. (* Example Usage:
  86.     Find_object_in_window( 9, 46); #first file
  87.     throw_trash();
  88.  *)